package com.leetcode.LC;

import java.util.HashSet;

public class LC965 {
    HashSet<Integer> set = new HashSet<>();
    public boolean isUnivalTree(TreeNode root) {
        qinaxuDigui(root);

        return set.size()==1?true:false;
    }

    // 用递归的方法进行先序遍历
    public void qinaxuDigui(TreeNode treeNode) {
        set.add(treeNode.val);
        if (treeNode.left != null) {
            qinaxuDigui(treeNode.left);
        }
        if (treeNode.right != null) {
            qinaxuDigui(treeNode.right);
        }
    }

}
